# -*- coding: utf-8 -*-

import os
from flask import Flask
from flask_mongoengine import MongoEngine, MongoEngineSessionInterface
from flask_login import LoginManager

from api.config import current_config
from settings import STATIC_PATH

mongodb = MongoEngine()
login_manager = LoginManager()


def create_simple_app():
    _config = os.getenv('FLASK_CONFIG') or 'api.config.DevConfig'
    app = Flask(__name__, static_folder=STATIC_PATH)

    app.config.from_object(_config)
    # init mongodb
    mongodb.init_app(app)
    app.session_interface = MongoEngineSessionInterface(mongodb)  # sessions w/ mongoengine
    login_manager.init_app(app)

    return app


def create_app(config=None):
    _config = config or os.getenv('FLASK_CONFIG') or 'api.config.DevConfig'
    app = Flask(__name__)

    app.config.from_object(_config)

    # init mongodb
    mongodb.init_app(app)
    return app
